package TUILayer;

import ModelLayer.*;
import ControlLayer.*;
import java.util.Scanner;
/**
 * Write a description of class Menu here.
 * 
 * @author (Kis Boisen Hansen) 
 * @version (2010.04.08, 2012.04.10)
 */
public class Menu
{
   public Menu()
   {
       mainMenuStart();
   }
    public void mainMenuStart()
   {
        boolean exit=false;
        while (!exit) //! means while exit not is true (that is: false)
        {
            int choise = writeMainMenu();
            if(choise == 1)
            {
                startCD();
            }
            else{
                 if(choise == 2){ 
                        startFindCD();
                 }
                 else{
                     if(choise == 3){
                      startAddNumber();
                            }//end if
                     else{
                         writeEnd();
                        exit = true;
                      }//end else
                 }// end else
             }//end else
        }//end while
    }//end start
    
   private int writeMainMenu()
    {       
            // creates a keyboard object to read input
            Scanner keyboard = new Scanner(System.in);
            System.out.println("\f *** MainMenu ***");
            System.out.println(" (1)Create CD");
            System.out.println(" (2)Find CD");
            System.out.println(" (3)Add number on CD ");
            System.out.println(" (4) Close");
            System.out.print("\n Make your choise: ");
            
            int choise = keyboard.nextInt();
            
            return choise;
    }
    
    private void startCD()
    {
       Scanner keyboard = new Scanner(System.in);
       System.out.println("Input CD#");
       int indCDNr = keyboard.nextInt();
       System.out.println("Input title ");
       String indTitel = keyboard.next();
       CDHandling cdCtrl = new CDHandling();
       cdCtrl.createCD(indCDNr,indTitel);
           
      
       
    }

    private void startAddNumber()
    {
       Scanner keyboard = new Scanner(System.in);
       System.out.println("Input cd title");
       String indTitel = keyboard.nextLine();
       System.out.println("input the title on the number ");
       String indTrack = keyboard.nextLine();
       System.out.println("Input playing time ");
      int length = keyboard.nextInt();
       CDHandling cdCtrl = new CDHandling();
       cdCtrl.addTrack(indTitel,indTrack,length);
       
    }
    private void startFindCD()
    {
       Scanner keyboard = new Scanner(System.in);
       System.out.println("Input CD title ");
       String title = keyboard.next();
       CDHandling cdCtrl = new CDHandling();
       CD cdObj = cdCtrl.findCD(title);
       if(cdObj != null)
       {
           System.out.println("CD information ");
           System.out.println("Title : "+ cdObj.getTitle());
           System.out.println("Numbers on the cd " + cdObj.getAntalNumre());
        }
        else{
            System.out.println("CD er ikke fundet");
        }
       pause();
    }
    private void writeEnd()
    {
        System.out.println(" The System is shuting down ");
    }
    private void pause()
    {
       Scanner keyboard = new Scanner(System.in);
       String vent = keyboard.nextLine();
    }
    
 }
